home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / misc.zoo / misc / lasergrafix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  2.4 KB  |  77 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /* convert a mgr window dump to lasergrafix format version 4 */
  9.  
  10. /*    $Header: lasergrafix.c,v 4.1 88/08/24 15:54:08 bianchi Exp $
  11.     $Source: /tmp/mgrsrc/misc/RCS/lasergrafix.c,v $
  12. */
  13. static char    RCSid_[] = "$Source: /tmp/mgrsrc/misc/RCS/lasergrafix.c,v $$Revision: 4.1 $";
  14.  
  15. #include <stdio.h>
  16.  
  17. #define WIDE    (30*85)                /* pixels/page */
  18. #define HIGH    (30*115)            /* pixels/page */
  19. #define HEX(x)    ((x)<10?(x)+'0':(x)-10+'A')
  20.  
  21. main(argc,argv)
  22. int argc;
  23. char **argv;
  24.    {
  25.    register int c,count=0, byte;
  26.    int w,h,d,bytesperline;
  27.    int scale = 2;
  28.  
  29.    /* read in bitmap header */
  30.  
  31.    if (!bitmaphead( stdin, &w, &h, &d, &bytesperline )) {
  32.       fprintf(stderr,"%s: invalid bitmap format \n",*argv);
  33.       exit(1);
  34.       }
  35.  
  36.    printf("\r^PY^-\r");                /* new page */
  37.    printf("^PY^,");                /* new page */
  38.    printf("^IJ%.5d^IT%.5d",
  39.          (HIGH-h*scale)/2,(WIDE-w*scale)/2);    /* center picture */
  40.    printf("^IP0%d0%d",scale,scale);        /* expand by 2x2 */
  41.    printf("^P%.4d", bytesperline*8);        /* plot "w" dots/row */
  42.  
  43.    while((c=getchar()) != EOF) {
  44.       if (count==0) {
  45.           count=1;
  46.           byte=c;
  47.           }
  48.       else if (c==byte && count<999) {
  49.           count++;
  50.           }
  51.       else {
  52.           switch(count) {
  53.              case 3:  putchar(HEX(byte>>4)), putchar(HEX(byte&017));
  54.              case 2:  putchar(HEX(byte>>4)), putchar(HEX(byte&017));
  55.              case 1:  putchar(HEX(byte>>4)), putchar(HEX(byte&017));
  56.                       break;
  57.              default: printf("^C%03d%c%c",count,HEX(byte>>4),HEX(byte&017));
  58.              }
  59.           count=1;
  60.           byte=c;
  61.           }
  62.       }
  63.    /* flush the rest of the picture */
  64.  
  65.    switch(count) {
  66.       case 3:  putchar(HEX(byte>>4)), putchar(HEX(byte&017));
  67.       case 2:  putchar(HEX(byte>>4)), putchar(HEX(byte&017));
  68.       case 1:  putchar(HEX(byte>>4)), putchar(HEX(byte&017));
  69.                break;
  70.       default: printf("^C%03d%c%c",count,HEX(byte>>4),HEX(byte&017));
  71.       }
  72.  
  73.    printf("^G^,");            /* print the page */
  74.    printf("\r^PY^-\r");            /* new page */
  75.    exit(0);
  76.    }
  77.